// pages/mySelfTask.js
const app = getApp()
let page1 = 1;
let page2 = 1;
let self;
Page({
  /**
   * 页面的初始数据
   */
  data: {
    currentIndex: 0,
    "taskList1": [],
    "taskList2": []
  },
  pagechange: function (e) {
    if ("touch" === e.detail.source) {
      this.setData({
        currentIndex: e.detail.current
      })
    }
  },
  titleClick: function (e) {
    let currentPageIndex =
      this.setData({
        //拿到当前索引并动态改变
        currentIndex: e.currentTarget.dataset.idx
      })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    self = this;
    page1 = 1;
    page2 = 1;
    this.setData({currentIndex:options.index});
    toPage1(1);
    toPage2(1);
    
  },

  queryPage1:function(){
    toPage1(page1);
  },

  queryPage2:function(){
    toPage2(page2)
  },


  goDetaily(e) {
    let taskId = e.currentTarget.dataset.taskid;
    wx.navigateTo({
      url:'../selfTaskDetaily/selfTaskDetaily?taskId='+taskId
    })
  },

  goTakeDetaily(e) {
    let taskId = e.currentTarget.dataset.taskid;
    wx.navigateTo({
      url: '../takeTaskDetaily/takeTaskDetaily?taskId='+taskId+"&type=personal"
    })
  }
})

function toPage1(page){
    wx.request({
      url:app.globalData.prefix+"/taskAction/takeTaskListPerson.do?page="+page1+"&pageSize=20&openId="+app.globalData.userInfo.openId,
      success:function(res){
        if(res.data.status!='00'){
          wx.$showToast("系统错误");
          return;
        }
        self.setData({taskList1:self.data.taskList1.concat(res.data.result)});
        page1++;
      }
    });
}

function toPage2(page){
  wx.request({
    url:app.globalData.prefix+"/taskAction/publishTaskList.do?openId="+app.globalData.userInfo.openId+"&page="+page2+"&pageSize=20",
    success:function(res){
      if(res.data.status!='00'){
        wx.$showToast("系统错误");
        return;
      }
      self.setData({taskList2:self.data.taskList2.concat(res.data.result)});
      page2++;
      console.log(res.data.result);
    }
  });
}